package com.gss.stockLedger.domain;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.format.datetime.DateFormatter;

import com.gss.stockLedger.service.FIFOReportGenerationService;

public class FIFOReportDTO implements Comparable<FIFOReportDTO> {
	
	private String partId;	//0
	private String partDesc; //1
	private String sapDocNo; //2
	private String sapEntryDate; //3
	private String assignmentId; //4
	private String strTransactionDate; //5
	private Date transactionDate; 
	private String invoiceNo; //6
	private String strInvoiceDate; //7
	private String vendorCode; //8
	private String vendorName; //9
	private String inventoryType; //10
	private String transactionType; //11
	private String acctType; //12 
	private Long quantity; //13
	private Float rate; //14
	private Double value; //15
	private String purchaseType; //16
	private Double valueFCY; //17
	private String unitFCY; //18

	
//	private Date assignmentDate;	
//	private String grnId;	
//	private Date receiptDate;	
	
	private Long closingQuantity;
	private Float closingRate;
	private Double closingValue;
	public boolean printClosingStats = false;
	
	

	public String getPartId() {
		return partId;
	}
	public String getPartDesc() {
		return partDesc;
	}
	public String getSapDocNo() {
		return sapDocNo;
	}
	public String getSapEntryDate() {
		return sapEntryDate;
	}
	public String getAssignmentId() {
		return assignmentId;
	}
	public String getStrTransactionDate() {
		return strTransactionDate;
	}
	public Date getTransactionDate() {
		return transactionDate;
	}
	public String getInvoiceNo() {
		return invoiceNo;
	}
	public String getStrInvoiceDate() {
		return strInvoiceDate;
	}
	public String getVendorCode() {
		return vendorCode;
	}
	public String getVendorName() {
		return vendorName;
	}
	public String getInventoryType() {
		return inventoryType;
	}
	public String getTransactionType() {
		return transactionType;
	}
	public String getAcctType() {
		return acctType;
	}
	public Long getQuantity() {
		return quantity;
	}
	public Float getRate() {
		return rate;
	}
	public Double getValue() {
		return value;
	}
	public String getPurchaseType() {
		return purchaseType;
	}
	public Double getValueFCY() {
		return valueFCY;
	}
	public String getUnitFCY() {
		return unitFCY;
	}
	public Long getClosingQuantity() {
		return closingQuantity;
	}
	public Float getClosingRate() {
		return closingRate;
	}
	public Double getClosingValue() {
		return closingValue;
	}
	public void setPartId(String partId) {
		this.partId = partId;
	}
	public void setPartDesc(String partDesc) {
		this.partDesc = partDesc;
	}
	public void setSapDocNo(String sapDocNo) {
		this.sapDocNo = sapDocNo;
	}
	public void setSapEntryDate(String sapEntryDate) {
		this.sapEntryDate = sapEntryDate;
	}
	public void setAssignmentId(String assignmentId) {
		this.assignmentId = assignmentId;
	}
	public void setStrTransactionDate(String strTransactionDate) {
		this.strTransactionDate = strTransactionDate;
	}
	public void setTransactionDate(Date transactionDate) {
		this.transactionDate = transactionDate;
	}
	public void setInvoiceNo(String invoiceNo) {
		this.invoiceNo = invoiceNo;
	}
	public void setStrInvoiceDate(String strInvoiceDate) {
		this.strInvoiceDate = strInvoiceDate;
	}
	public void setVendorCode(String vendorCode) {
		this.vendorCode = vendorCode;
	}
	public void setVendorName(String vendorName) {
		this.vendorName = vendorName;
	}
	public void setInventoryType(String inventoryType) {
		this.inventoryType = inventoryType;
	}
	public void setTransactionType(String transactionType) {
		this.transactionType = transactionType;
	}
	public void setAcctType(String acctType) {
		this.acctType = acctType;
	}
	public void setQuantity(Long quantity) {
		this.quantity = quantity;
	}
	public void setRate(Float rate) {
		this.rate = rate;
	}
	public void setValue(Double value) {
		this.value = value;
	}
	public void setPurchaseType(String purchaseType) {
		this.purchaseType = purchaseType;
	}
	public void setValueFCY(Double valueFCY) {
		this.valueFCY = valueFCY;
	}
	public void setUnitFCY(String unitFCY) {
		this.unitFCY = unitFCY;
	}
	public void setClosingQuantity(Long closingQuantity) {
		this.closingQuantity = closingQuantity;
	}
	public void setClosingRate(Float closingRate) {
		this.closingRate = closingRate;
	}
	public void setClosingValue(Double closingValue) {
		this.closingValue = closingValue;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		DecimalFormat decimalFormat = new DecimalFormat("#0.00");
		SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MMM-yyyy");
		StringBuffer temp = new StringBuffer();
		temp.append(inventoryType);
		temp.append("~");
		temp.append(partId);
		temp.append("~");
		if(null!=partDesc)
			temp.append(partDesc);
		temp.append("~");
		if(null!=sapDocNo)
			temp.append(sapDocNo);
		temp.append("~");
		if(null!=sapEntryDate)
			temp.append(sapEntryDate);
		temp.append("~");
		if(null!=assignmentId)
			temp.append(assignmentId);
		temp.append("~");
		temp.append(dateFormatter.format(transactionDate));
		temp.append("~");
		if(null!=invoiceNo)
			temp.append(invoiceNo);
		temp.append("~");
		
		if(null!=strInvoiceDate)
			temp.append(strInvoiceDate);
		temp.append("~");
		
		if(null!=vendorCode)
			temp.append(vendorCode);
		temp.append("~");
		
		if(null!=vendorName)
			temp.append(vendorName);
		temp.append("~");
		
		if(null != valueFCY)
			temp.append(decimalFormat.format(valueFCY));
		temp.append("~");
		
		if(null != unitFCY)
			temp.append(unitFCY);
		temp.append("~");
		
		if(null != purchaseType)
			temp.append(purchaseType);
		temp.append("~");
		
		temp.append(transactionType);
		temp.append("~");

		temp.append(acctType);
		temp.append("~");
		
		if(FIFOReportGenerationService.Receipt_Transaction_Type.contains(transactionType)){
			if(null != quantity)
				temp.append(quantity);
			temp.append("~");
			if(null != rate)
				temp.append(decimalFormat.format(rate));
			temp.append("~");
			if(null != value)
				temp.append(decimalFormat.format(value));
			temp.append("~");
			temp.append("~");
			temp.append("~");
			temp.append("~");
		}else if(FIFOReportGenerationService.Consumption_Transaction_Type.contains(transactionType)){
			temp.append("~");
			temp.append("~");
			temp.append("~");
			if(null != quantity)
				temp.append(quantity);
			temp.append("~");
			if(null != rate)
				temp.append(decimalFormat.format(rate));
			temp.append("~");
			if(null != value)
				temp.append(decimalFormat.format(value));
			temp.append("~");
		}
		
		if(printClosingStats){
		temp.append(closingQuantity);
		temp.append("~");
		if(null != closingRate)
		temp.append(decimalFormat.format(closingRate));
		temp.append("~");
		if(null != closingValue)
		temp.append(decimalFormat.format(closingValue));
		temp.append("~");
		}else{
			temp.append("~");
			temp.append("~");
			temp.append("~");
		}

		return temp.toString() ;
	}
	@Override
	public int compareTo(FIFOReportDTO o) {
		
		if(this.getTransactionDate().compareTo(o.getTransactionDate())>=0)
			return 1;
		else
			return 0;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof FIFOReportDTO)
		{
			FIFOReportDTO fifoReportDTO = (FIFOReportDTO)obj;
			if(fifoReportDTO.getTransactionType().equalsIgnoreCase("ZGRIR")&&
					fifoReportDTO.getTransactionType().equalsIgnoreCase(this.getTransactionType()))
				{
					if(fifoReportDTO.getAssignmentId().equalsIgnoreCase(this.getAssignmentId()))
						return true;
				}
				
		}
		
		return false;
	}
	

}
